<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Yuedu_model extends CI_Model{
	var $CI;
	function __construct($table=''){
  		parent::__construct();
  		$this->CI =& get_instance();
  		$this->CI->load->model('Data_model');
		$this->CI->load->library ('mysession');
		$this->CI->load->helper ('myfunc');
	}
	
	function insertData(){
		/*
		 * $data为模拟数据
		 */
		$data = array (
			$tb_article = array(
			
					'categoryid'=>1,
					'title'=>'test article title',
					'content'=>'test article content',
					'createtime'=>time(),
					'updatetime'=>time(),
					'remark'=>'test article remark'
		),
				$tb_question = array(
			
						array(
								'articleid'=>1,
								'content'=>'test question content1',
								'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question remark1',
								'questiontype' => 1,
								'answer'=>'A',
				),
						array(
								'articleid'=>1,
								'content'=>'test question content2',
								'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question remark2',
								'questiontype' => 1,
								'answer'=>'B',
				),
						array(
								'articleid'=>1,
								'content'=>'test question content3',
								'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question remark3',
								'questiontype' => 1,
								'answer'=>'C',
				),
		),
				$tb_question_option = array(
					    array(
					
					    		'questionid'=>1,
					    		'code' =>'A',
					    		'content'=>'A option content',
					    		'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question_optoin remarkA',
				),
						array(
					
								'questionid'=>1,
								'code' =>'B',
								'content'=>'B option content',
								'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question_optoin remarkB',
				),
						array(
						
								'questionid'=>1,
								'code' =>'C',
								'content'=>'C option content',
								'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question_optoin remarkC',
				),
						array(
					
								'questionid'=>1,
								'code' =>'D',
								'content'=>'D option content',
								'createtime'=>time(),
								'updatetime' => time(),
								'remark' => 'test question_optoin remarkD',
				),
						
				),
				
		) ;
		
		/*
		 * 将$data的数据循环插入到三张表中
		 */
		foreach($data as $key=>$value){
			
			if(arrayLevel($value) == 1){//如果是一维数组直接插入
				
				$this->data_model->addData($value,$key);
				
			}else{//否则为二维数组，对应在tb_question和tb_question_option两张表中
				
				foreach($value as $item){
					$this->data_model->addData($item,$key);
				}
			}
		}//循环插入结束	
		
	}
	
/**
 * 返回数组的维度
 * @param  [type] $arr [description]
 * @return [type]      [description]
 */
function arrayLevel($arr){
    $al = array(0);
    function aL($arr,&$al,$level=0){
        if(is_array($arr)){
            $level++;
            $al[] = $level;
            foreach($arr as $v){
                aL($v,$al,$level);
            }
        }
    }
    aL($arr,$al);
    return max($al);
}

function add($article){
	
}
	
}